package com.my.demo.controller;


import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

@RestController
public class TestSync {


    @GetMapping("syncTest")
    public void test() throws ExecutionException, InterruptedException {
        System.out.println(1);
        CompletableFuture<String> objectCompletableFuture = CompletableFuture.supplyAsync(() -> {
            System.out.println(2);
            try {
                Thread.sleep(3111);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return null;
        });
        CompletableFuture<String> objectCompletableFuture2 = CompletableFuture.supplyAsync(() -> {
            System.out.println(222);
            try {
                Thread.sleep(3111);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return null;
        });
            objectCompletableFuture.get();

        System.out.println(3);
    }
}
